home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / comm / bbs / wwbbs31_source.lha / Hydra / async.asm < prev    next >
Assembly Source File  |  1994-06-28  |  24KB  |  741 lines

  1. ;==============================================================================
  2. ;
  3. ;                             HydraCom Version 1.00
  4. ;
  5. ;                        A sample implementation of the
  6. ;                  HYDRA Bi-Directional File Transfer Protocol
  7. ;
  8. ;                            HydraCom was written by
  9. ;                  Arjen G. Lentz, LENTZ SOFTWARE-DEVELOPMENT
  10. ;                 COPYRIGHT (C) 1991-1993; ALL RIGHTS RESERVED
  11. ;
  12. ;                      The HYDRA protocol was designed by
  13. ;                Arjen G. Lentz, LENTZ SOFTWARE-DEVELOPMENT and
  14. ;                            Joaquim H. Homrighausen
  15. ;                 COPYRIGHT (C) 1991-1993; ALL RIGHTS RESERVED
  16. ;
  17. ;
  18. ; Revision history:
  19. ; 06 Sep 1991 - (AGL) First tryout
  20. ; .. ... .... - Internal development
  21. ; 11 Jan 1993 - HydraCom version 1.00, Hydra revision 001 (01 Dec 1992)
  22. ;
  23. ;
  24. ; For complete details of the Hydra and HydraCom licensing restrictions,
  25. ; please refer to the license agreements which are published in their entirety
  26. ; in HYDRACOM.C and LICENSE.DOC, and also contained in the documentation file
  27. ; HYDRACOM.DOC
  28. ;
  29. ; Use of this file is subject to the restrictions contained in the Hydra and
  30. ; HydraCom licensing agreements. If you do not find the text of this agreement
  31. ; in any of the aforementioned files, or if you do not have these files, you
  32. ; should immediately contact LENTZ SOFTWARE-DEVELOPMENT and/or Joaquim
  33. ; Homrighausen at one of the addresses listed below. In no event should you
  34. ; proceed to use this file without having accepted the terms of the Hydra and
  35. ; HydraCom licensing agreements, or such other agreement as you are able to
  36. ; reach with LENTZ SOFTWARE-DEVELOMENT and Joaquim Homrighausen.
  37. ;
  38. ;
  39. ; Hydra protocol design and HydraCom driver:         Hydra protocol design:
  40. ; Arjen G. Lentz                                     Joaquim H. Homrighausen
  41. ; LENTZ SOFTWARE-DEVELOPMENT                         389, route d'Arlon
  42. ; Langegracht 7B                                     L-8011 Strassen
  43. ; 3811 BT  Amersfoort                                Luxembourg
  44. ; The Netherlands
  45. ; FidoNet 2:283/512, AINEX-BBS +31-33-633916         FidoNet 2:270/17
  46. ; arjen_lentz@f512.n283.z2.fidonet.org               joho@ae.lu
  47. ;
  48. ; Please feel free to contact us at any time to share your comments about our
  49. ; software and/or licensing policies.
  50. ;
  51. ;==============================================================================
  52.  
  53.  
  54.           IDEAL
  55.  
  56. IFDEF MODL
  57.           MODEL MODL
  58. ELSEIFDEF _SMALL
  59.           MODEL SMALL
  60. ELSEIFDEF _LARGE
  61.           MODEL LARGE
  62. ENDIF
  63.  
  64.  
  65. EOI             equ     020h                    ; 8259 end-of-interupt
  66. Ctrl8259_0      equ     020h                    ; 8259 port
  67. Ctrl8259_1      equ     021h                    ; 8259 port (Masks)
  68. BufSize         equ     4100                    ; Buffer Size
  69.  
  70.  
  71.  
  72.  
  73.         DATASEG
  74.  
  75. ; Various things to be set upon AsyncInit()
  76. VectorNum       db      ?                       ; Vector Number
  77. EnableIRQ       db      ?                       ; Mask to enable 8259 IRQ
  78. DisableIRQ      db      ?                       ; Mask to disable 8259 IRQ
  79. VectorSeg       dw      ?                       ; Old Vector Segment
  80. VectorOfs       dw      ?                       ; Old Vector Offset
  81.  
  82. Fifo            db      ?                       ; Nonzero if 16550 FIFO enabled
  83. CTShand         dw      ?                       ; Nonzero if CTS handshaking ok
  84.  
  85. ; Register Addresses for the 8250 UART
  86. Port            dw      ?                       ; Port Base Address
  87. LABEL RegStart word
  88. THR             dw      ?                       ; Transmitter Holding Register
  89. RDR             dw      ?                       ; Receiver Data Register
  90. BRDL            dw      ?                       ; Baud Rate Divisor, Low byte
  91. BRDH            dw      ?                       ; Baud Rate Divisor, High Byte
  92. IER             dw      ?                       ; Interupt Enable Register
  93. IIR             dw      ?                       ; Interupt Identification Reg
  94. FCR             dw      ?                       ; FIFO Control Register
  95. LCR             dw      ?                       ; Line Control Register
  96. MCR             dw      ?                       ; Modem Control Register
  97. LSR             dw      ?                       ; Line Status Register
  98. MSR             dw      ?                       ; Modem Status Register
  99. ; Register Offsets for the UART
  100. RegOffsets      dw      0, 0, 0, 1, 1, 2, 2, 3, 4, 5, 6
  101.  
  102. ; Buffer Data
  103. RecBuffer       db      BufSize DUP (?)         ; Receive Buffer
  104. RecHead         dw      ?                       ; Buffer Head Pointer
  105. RecTail         dw      ?                       ; Buffer Tail Pointer
  106. TransBuffer     db      BufSize DUP (?)         ; Transmit Buffer
  107. TransHead       dw      ?                       ; Buffer Head Pointer
  108. TransTail       dw      ?                       ; Buffer Tail Pointer
  109.  
  110.  
  111.         CODESEG
  112.  
  113.         PUBLIC  _AsyncInit,     _AsyncDump,     _AsyncPurge,    _AsyncStop
  114.         PUBLIC  _AsyncIn,       _AsyncOut,      _AsyncSet
  115.         PUBLIC  _AsyncHand,     _AsyncStat,     _AsyncInStat
  116.         PUBLIC  _AsyncOutStat,  _AsyncCTS,      _AsyncFifo
  117.  
  118.  
  119. ;-----------------------------------------------------------------------------
  120. ; AsyncDump                                          Empty the transmit buffer
  121. ;-----------------------------------------------------------------------------
  122. ; void  AsyncDump (void);
  123. ;
  124. ;
  125. ;-----------------------------------------------------------------------------
  126. PROC    _AsyncDump
  127.         cli
  128.         push    ax
  129.         mov     ax, offset TransBuffer
  130.         mov     [TransHead], ax
  131.         mov     [TransTail], ax
  132.         pop     ax
  133.         sti
  134.         ret
  135. ENDP    _AsyncDump
  136.  
  137.  
  138.  
  139. ;-----------------------------------------------------------------------------
  140. ; AsyncPurge                                          Empty the receive buffer
  141. ;-----------------------------------------------------------------------------
  142. ; void  AsyncPurge (void);
  143. ;
  144. ;
  145. ;-----------------------------------------------------------------------------
  146. PROC    _AsyncPurge
  147.         cli
  148.         push    ax
  149.         mov     ax, offset RecBuffer
  150.         mov     [RecHead], ax
  151.         mov     [RecTail], ax
  152.         pop     ax
  153.         sti
  154.         ret
  155. ENDP    _AsyncPurge
  156.  
  157.  
  158.  
  159. ;-----------------------------------------------------------------------------
  160. ; AsyncInit                              Initalize Serial Port and install ISR
  161. ;-----------------------------------------------------------------------------
  162. ;       void    AsyncInit( int port)
  163. ;
  164. ;       Where Port is
  165. ;               0  =  COM1
  166. ;               1  =  COM2
  167. ;               2  =  COM3
  168. ;               3  =  COM4
  169. ;
  170. ;-----------------------------------------------------------------------------
  171. PROC    _AsyncInit
  172.         ARG     CommPort:word
  173.  
  174.         push    bp
  175.         mov     bp, sp
  176.  
  177. ;---- Set various things according to com port number
  178.         mov     ax, [CommPort]
  179.  
  180. ;----- COM1
  181.         cmp     ax, 0
  182.         jne     @@1
  183.         mov     [Port], 03F8h
  184.         mov     [VectorNum], 0Ch
  185.         mov     [EnableIRQ], 0EFh
  186.         mov     [DisableIRQ], 10h
  187.         jmp     short @@Done
  188. @@1:
  189. ;----- COM2
  190.         cmp     ax, 1
  191.         jne     @@2
  192.         mov     [Port], 02F8h
  193.         mov     [VectorNum], 0Bh
  194.         mov     [EnableIRQ], 0F7h
  195.         mov     [DisableIRQ], 08h
  196.         jmp     short @@Done
  197. @@2:
  198. ;----- COM3
  199.         cmp     ax, 2                           ; 2
  200.         jne     @@3
  201.         mov     [Port], 03E8h                   ; 03E8
  202.         mov     [VectorNum], 0Ch                ; 0C
  203.         mov     [EnableIRQ], 0EFh               ; EF
  204.         mov     [DisableIRQ], 10h               ; 10
  205.         jmp     short @@Done
  206. @@3:
  207. ;----- COM4
  208.         mov     [Port], 02E8h                   ; 02E8
  209.         mov     [VectorNum], 0Bh                ; 0B
  210.         mov     [EnableIRQ], 0F7h               ; F7
  211.         mov     [DisableIRQ], 08h               ; 08
  212. @@Done:
  213.  
  214. ;---- Compute Register locations
  215.         mov     cx, 11
  216.         mov     bx, offset RegOffsets
  217.         push    di
  218.         mov     di, offset RegStart
  219. @@4:
  220.         mov     ax, [bx]
  221.         add     ax, [Port]
  222.         mov     [di], ax
  223.         add     bx, 2
  224.         add     di, 2
  225.         loop    @@4
  226.  
  227.         pop     di
  228.  
  229.  
  230. ;----- Initalize Buffers
  231.         call    _AsyncDump
  232.         call    _AsyncPurge
  233.  
  234. ;--- Save and reassign interrupt vector
  235.         push    ds                      ; Save Old Vector
  236.         mov     al,[VectorNum]
  237.         mov     ah,35h
  238.         int     21h
  239.         mov     [VectorSeg], es
  240.         mov     [VectorOfs], bx
  241.  
  242.         mov     al, [VectorNum]
  243.         push    cs                      ; Set New Vector
  244.         pop     ds
  245.         mov     dx, offset AsyncISR
  246.         mov     ah, 25h
  247.         int     21h
  248.         pop     ds
  249.  
  250. ;----- Enable 8259 interrupt (IRQ) line for this async adapter
  251.         in      al, Ctrl8259_1
  252.         and     al, [EnableIRQ]
  253.         out     Ctrl8259_1, al
  254.  
  255. ;----- Enable 8250 Interrupt-on-data-ready
  256.         mov     dx, [LCR]               ; Read Line control register and clear
  257.         in      al, dx                  ; bit 7, the Divisor Latch Address
  258.         and     al, 07Fh
  259.         out     dx, al
  260.  
  261.         mov     dx, [IER]
  262.         mov     al, 0                   ; we're gonna test the UART first
  263.         out     dx, al
  264.         in      al, dx                  ; if this isn't 0, there's no UART
  265.         cmp     al, 0
  266.         jnz     @@222
  267.  
  268.         mov     al, 3
  269.         out     dx, al
  270.  
  271. ;----- Try to enable 16550 FIFOs
  272.         mov     dx, [FCR]               ; FIFO Control Register
  273.         mov     al, 0C7h                ; bits 76210 (trigger14,clearIO,enable)
  274.         out     dx, al                  ; Write
  275.         mov     dx, [IIR]
  276.         in      al, dx
  277.         and     al, 0C0h                ; 8250/16450 sets none of the 2 bits
  278.         cmp     al, 0C0h                ; faulty 16550 sets 1 of the 2 bits
  279.         je      okfifo
  280.         mov     dx, [FCR]               ; didn't work, turn off case faulty 550
  281.         xor     al, al                  ; set to zero = no FIFO
  282.         out     dx, al
  283. okfifo: mov     [Fifo], al              ; store 16550 FIFO situation
  284.  
  285. ;----- Reset CTS handshaking flag
  286.         mov     [CTShand], 0            ; Disable CTS handshaking
  287.  
  288. ;----- Clear 8250 Status and data registers
  289. @@10:
  290.         mov     dx, [RDR]               ; Clear RDR by reading port
  291.         in      al, dx
  292.         mov     dx, [LSR]               ; Clear LSR
  293.         in      al, dx
  294.         mov     dx, [MSR]               ; Clear MSR
  295.         in      al, dx
  296.         mov     dx, [IIR]               ; Clear IIR
  297.         in      al, dx
  298.         test    al, 1
  299.         jz      @@10
  300.  
  301. ;----- Set Bit 3 of MCR -- Enable interupts, also raise DTR and RTS
  302.         mov     dx, [MCR]
  303.         in      al, dx
  304.         or      al, 0Bh
  305.         out     dx, al
  306.  
  307. ;----- Clear Buffers Just in case
  308.         call    _AsyncDump
  309.         call    _AsyncPurge
  310.  
  311. ;----- Return
  312.         xor     ax, ax
  313. @@222:
  314.         pop     bp
  315.         ret
  316. ENDP    _AsyncInit
  317.  
  318.  
  319.  
  320. ;-----------------------------------------------------------------------------
  321. ;  AsyncStop                                                     Uninstall ISR
  322. ;-----------------------------------------------------------------------------
  323. ;       void  AsyncStop( void)
  324. ;-----------------------------------------------------------------------------
  325. PROC    _AsyncStop
  326.         push    bp
  327.         mov     bp, sp
  328.  
  329. ;----- Mask (disable) 8259 IRQ Interrupt
  330.         in      al, Ctrl8259_1
  331.         or      al, [DisableIRQ]
  332.         out     Ctrl8259_1, al
  333.  
  334. ;----- Disable 8250 interrupt
  335.         mov     dx, [LCR]
  336.         in      al, dx
  337.         and     al, 07Fh
  338.         out     dx, al
  339.         mov     dx, [IER]
  340.         xor     al, al
  341.         out     dx, al
  342.  
  343. ;----- Set bit 3 in MCR to 0
  344.         mov     dx, [MCR]
  345.         in      al, dx
  346.         and     al, 0F7h
  347.         out     dx, al
  348.  
  349. ;----- Disable 16550 FIFOs
  350.         mov     dx, [FCR]               ; FIFO Control Register
  351.         xor     al, al                  ; set to 0
  352.         out     dx, al                  ; Write
  353.  
  354. ;----- Interrupts are disables.  Restore saved interrupt vector.
  355.         push    ds
  356.         mov     al, [VectorNum]
  357.         mov     ah, 25h
  358.         mov     dx, [VectorOfs]
  359.         mov     ds, [VectorSeg]
  360.         int     21h
  361.         pop     ds
  362.  
  363. ;----- Return
  364.         pop     bp
  365.         ret
  366. ENDP    _AsyncStop
  367.  
  368.  
  369.  
  370. ;-----------------------------------------------------------------------------
  371. ; AsyncISR                                     Async Interrupt Service Routine
  372. ;-----------------------------------------------------------------------------
  373. ;       To be called only as an interrupt.
  374. ;-----------------------------------------------------------------------------
  375. PROC    AsyncISR
  376.         sti
  377.  
  378.         push    ax                      ; Save Registers
  379.         push    bx
  380.         push    cx
  381.         push    ds
  382.         push    dx
  383.  
  384.         mov     ax, @data               ; Address local data with ds
  385.         mov     ds, ax
  386.  
  387. @@isr:  mov     dx, [IIR]               ; Check if data actually received
  388.         in      al, dx
  389.         and     al, 07h
  390.         test    al, 1
  391.         jnz     @@end
  392.         cmp     al, 04h                 ; Receive interrupt
  393.         je      @@receive
  394.         cmp     al, 02h
  395.         je      @@transmit              ; Transmit interrupt
  396.         cmp     al, 0
  397.         je      @@modem                 ; Modem Status interrupt
  398.  
  399. @@end:  cli
  400.  
  401.         mov     al, EOI                 ; Signal end of interrupt
  402.         out     Ctrl8259_0, al
  403.  
  404.         ; Disable and re-enable interrupts so that there
  405.         ; is an interrupt edge.
  406.  
  407. ;       mov     dx,[IER]                ; Point to Interrupt Enable Register.
  408. ;       in      al,dx                   ; Read the current value.
  409. ;       push    ax                      ; Save it.
  410. ;       mov     al,0                    ; Disable the interrupts.
  411. ;       out     dx,al
  412. ;       pop     ax                      ; Restore original mask.
  413. ;       out     dx,al                   ; Re-enable interrupts.
  414.  
  415.         pop     dx                      ; Restore saved registers.
  416.         pop     ds
  417.         pop     cx
  418.         pop     bx
  419.         pop     ax
  420.  
  421.         iret
  422.  
  423. ;----- Receive a byte
  424. @@receive:
  425.         mov     dx, [RDR]               ; Get Byte
  426.         in      al, dx
  427.         mov     bx, [RecHead]           ; Store Byte in buffer
  428.         mov     [byte ptr bx], al
  429.         inc     bx                      ; Update RecHead
  430.         cmp     bx, offset RecBuffer + BufSize
  431.         jb      @@10
  432.         mov     bx, offset RecBuffer
  433. @@10:
  434.         cmp     bx, [RecTail]
  435.         jne     @@20
  436.         mov     bx, [RecHead]           ; Cancel Pointer advance on overflow
  437. @@20:
  438.         mov     [RecHead], bx           ; Store new pointer
  439.  
  440.         mov     dx, [LSR]               ; Read Line Status Register
  441.         in      al, dx
  442.         test    al, 01h                 ; Check for more Data Ready
  443.         jnz     @@receive               ; Will mostly happen in FIFO mode
  444.         jmp     short @@isr
  445.  
  446. ;----- Modem Status Interrupt - for CTS handshake handling
  447. @@modem:
  448.         mov     dx, [MSR]               ; Modem Status Register
  449.         in      al, dx
  450.         test    al, 010h                ; Clear To Send went high?
  451.         jz      @@isr                   ; Nope, some other line went somewhere
  452.  
  453.         mov     dx, [IER]               ; Point to Interrupt Enable Register.
  454.         mov     al, 03h                 ; RD was on, TD now on, MS now off.
  455.         out     dx, al
  456. ; fallthrough modem to transmit, CTS went high and THR must have been empty
  457.  
  458. ;----- Transmit A byte
  459. @@transmit:
  460.         mov     cx, 1                   ; Assume no FIFO, xmit one char
  461.         mov     al, [Fifo]
  462.         or      al, al
  463.         jz      @@xtop                  ; Not FIFO mode
  464.         mov     cx, 16                  ; FIFO, can transmit max 16 chars
  465.  
  466. @@xtop:
  467.         mov     bx, [TransTail]
  468.         cmp     bx, [TransHead]
  469.         jne     @@1
  470.  
  471.         mov     dx, [IER]               ; Buffer empty
  472.         mov     al, 1
  473.         out     dx, al                  ; Disable THR empty interrupt
  474.         jmp     @@isr
  475.  
  476. @@1:
  477.         mov     ax, [CTShand]
  478.         or      ax, ax
  479.         jz      @@xmit                  ; No handshaking, so ignore CTS
  480.  
  481.         mov     dx, [MSR]               ; Point to Modem Status Register.
  482.         in      al, dx                  ; Read the current value.
  483.         and     al, 010h                ; Check if CTS line high
  484.         jnz     @@xmit                  ; Yeo, so can transmit
  485.  
  486.         mov     dx, [IER]               ; No CTS, ask for irq on Modem Status
  487.         mov     al, 09h                 ; RD was on, TD now off, MS now on
  488.         out     dx, al
  489.         jmp     @@isr
  490.  
  491. @@xmit: mov     al, [byte ptr bx]       ; Get Byte
  492.         inc     [TransTail]             ; Update buffer pointer
  493.         cmp     [word ptr TransTail], offset TransBuffer + BufSize
  494.         jb      @@2
  495.         mov     [TransTail], offset TransBuffer
  496. @@2:
  497.         mov     dx, [THR]
  498.         out     dx, al
  499.         loopnz  @@xtop
  500.         jmp     @@isr
  501.  
  502. ENDP    AsyncISR
  503.  
  504.  
  505.  
  506. ;-----------------------------------------------------------------------------
  507. ;       AsyncIn                              Gets a byte from the input buffer
  508. ;-----------------------------------------------------------------------------
  509. ;       int     AsyncIn( void)
  510. ;-----------------------------------------------------------------------------
  511. PROC    _AsyncIn
  512.         push    bp
  513.         mov     bp, sp
  514.  
  515.         xor     ax, ax                          ; Pre-Set result to 0
  516.         mov     bx, [RecTail]
  517.         cmp     bx, [RecHead]
  518.         je      @@return
  519.         mov     al, [byte ptr bx]
  520.         inc     [RecTail]
  521.         cmp     [word ptr RecTail], offset RecBuffer + BufSize
  522.         jb      @@return
  523.         mov     [RecTail], offset RecBuffer
  524.  
  525. @@return:
  526.         pop     bp
  527.         ret
  528. ENDP    _AsyncIn
  529.  
  530.  
  531.  
  532. ;-----------------------------------------------------------------------------
  533. ;       AsyncOut                                Output a byte
  534. ;-----------------------------------------------------------------------------
  535. ;       void    AsyncOut( int c)
  536. ;-----------------------------------------------------------------------------
  537. PROC    _AsyncOut
  538.         ARG     CharOut:word
  539.  
  540.         push    bp
  541.         mov     bp, sp
  542.  
  543.         mov     ax, [CharOut]
  544.  
  545.         mov     bx, [TransHead]
  546.         mov     cx, bx
  547.         inc     cx                              ; Compute NEW buffer position
  548.         cmp     cx, offset TransBuffer + BufSize
  549.         jb      @@1
  550.         mov     cx, offset TransBuffer
  551. @@1:
  552.         cmp     cx, [TransTail]                 ; Wait for space in buffer
  553.         je      @@1
  554.  
  555.         mov     [byte ptr bx], al               ; Add byte to buffer
  556.         mov     [TransHead], cx                 ; Update pointer
  557.  
  558.         mov     dx, [IER]                       ; Enable THR empty interrupt
  559.         mov     al, 3
  560.         out     dx, al
  561.  
  562.         pop     bp
  563.         ret
  564. ENDP    _AsyncOut
  565.  
  566.  
  567.  
  568. ;-----------------------------------------------------------------------------
  569. ;       AsyncSet                                  Set communication paramaters
  570. ;-----------------------------------------------------------------------------
  571. ;       void    AsyncSet( word Baud, int Control)
  572. ;
  573. ;       Baud = 150, 300, 600, 1200, 2400, 4800, 9600, 19200, 28800, 38400, 57600
  574. ;       Control = The valure to place in the LCR
  575. ;-----------------------------------------------------------------------------
  576. PROC    _AsyncSet
  577.         ARG     Baud:word, Control:word
  578.  
  579.         push    bp
  580.         mov     bp, sp
  581.  
  582.         mov     bx, [Baud]
  583.         cmp     bx, 0
  584.         je      @@abort
  585.  
  586.         mov     ax, 0C200h              ; Baud rate divisor = 115200 / Baud
  587.         mov     dx, 0001h                       ; 115200 = 0001C200h
  588.         div     bx
  589.         mov     cx, ax
  590.  
  591.         cli
  592.         mov     dx, [LCR]               ; Set Port Toggle to BRDL/BRDH regs
  593.         mov     al, 0ffh
  594.         out     dx, al
  595.  
  596.         mov     dx, [BRDL]              ; Set Baud Rate
  597.         mov     al, cl
  598.         out     dx, al
  599.         mov     dx, [BRDH]
  600.         mov     al, ch
  601.         out     dx, al
  602.  
  603.         mov     dx, [LCR]                       ; Set LCR and Port Toggle
  604.         mov     ax, [Control]
  605.         and     al, 07Fh
  606.         out     dx, al
  607.  
  608.         sti
  609. @@abort:
  610.         pop     bp
  611.         ret
  612. ENDP    _AsyncSet
  613.  
  614.  
  615.  
  616. ;-----------------------------------------------------------------------------
  617. ;       AsyncInStat                      Returns the # of characters in buffer
  618. ;-----------------------------------------------------------------------------
  619. ;       int     AsyncInStat( void)
  620. ;-----------------------------------------------------------------------------
  621. PROC    _AsyncInStat
  622.         push    bp
  623.         mov     bp, sp
  624.  
  625.         mov     ax,[RecHead]
  626.         sub     ax, [RecTail]
  627.         jge     @@10
  628.         add     ax, BufSize
  629. @@10:
  630.  
  631.         pop     bp
  632.         ret
  633. ENDP    _AsyncInStat
  634.  
  635.  
  636.  
  637. ;-----------------------------------------------------------------------------
  638. ;       AsyncOutStat                     Returns the # of characters in buffer
  639. ;-----------------------------------------------------------------------------
  640. ;       int     AsyncOutStat( void)
  641. ;-----------------------------------------------------------------------------
  642. PROC    _AsyncOutStat
  643.         push    bp
  644.         mov     bp, sp
  645.  
  646.         mov     ax,[TransHead]
  647.         sub     ax, [TransTail]
  648.         jge     @@10
  649.         add     ax, BufSize
  650. @@10:
  651.  
  652.         pop     bp
  653.         ret
  654. ENDP    _AsyncOutStat
  655.  
  656.  
  657.  
  658. ;-----------------------------------------------------------------------------
  659. ;       AsyncHand                               Sets various handshaking lines
  660. ;-----------------------------------------------------------------------------
  661. ;       void    AsyncHand( int Hand)
  662. ;-----------------------------------------------------------------------------
  663. PROC    _AsyncHand
  664.         ARG     Hand:word
  665.         push    bp
  666.         mov     bp, sp
  667.  
  668.         mov     dx, [MCR]
  669.         mov     ax, [Hand]
  670.         or      al, 08h                         ; Keep interrupt enable ON
  671.         out     dx, al
  672.  
  673.         pop     bp
  674.         ret
  675. ENDP    _AsyncHand
  676.  
  677.  
  678.  
  679. ;-----------------------------------------------------------------------------
  680. ;       AsyncStat                                   Returns Async/Modem status
  681. ;-----------------------------------------------------------------------------
  682. ;       unsigned        AsyncStat (void)
  683. ;
  684. ;       MSR is returned in the high byte, LSR in the low byte
  685. ;-----------------------------------------------------------------------------
  686. PROC    _AsyncStat
  687.         push    bp
  688.         mov     bp, sp
  689.  
  690.         mov     dx, [MSR]
  691.         in      al, dx
  692.         mov     cl, al
  693.         mov     dx, [LSR]
  694.         in      al, dx                  ; LSR in low byte
  695.         mov     ah, cl                  ; MSR in high byte
  696.  
  697.         pop     bp
  698.         ret
  699. ENDP    _AsyncStat
  700.  
  701.  
  702. ;-----------------------------------------------------------------------------
  703. ;       AsyncCTS                                Enable/disable CTS handshaking
  704. ;-----------------------------------------------------------------------------
  705. ;       void    AsyncCTS( int enable)
  706. ;-----------------------------------------------------------------------------
  707. PROC    _AsyncCTS
  708.         ARG     enable:word
  709.         push    bp
  710.         mov     bp, sp
  711.  
  712.         mov     ax, [enable]
  713.         mov     [CTShand], ax
  714.  
  715.         pop     bp
  716.         ret
  717. ENDP    _AsyncCTS
  718.  
  719.  
  720.  
  721. ;-----------------------------------------------------------------------------
  722. ;       AsyncFifo                      Returns nonzero if 16550 (FIFO enabled)
  723. ;-----------------------------------------------------------------------------
  724. ;       unsigned        AsyncFifo (void)
  725. ;-----------------------------------------------------------------------------
  726. PROC    _AsyncFifo
  727.         push    bp
  728.         mov     bp, sp
  729.  
  730.         xor     ah, ah
  731.         mov     al, [Fifo]
  732.  
  733.         pop     bp
  734.         ret
  735. ENDP    _AsyncFifo
  736.  
  737.  
  738.         END
  739.  
  740. ; end of async.asm
  741.